package com.company.string;

import com.company.ListNode;

import java.util.ArrayList;
import java.util.List;
import java.util.Queue;

/**
 * @author jrue
 * @description
 * @date 2019/11/14 17:16
 * 回文
 */
public class IsPalindrome {

    public static void main(String[] args) {
        ListNode head = new ListNode(-129);
        head.next = new ListNode(-129);

        System.out.println(isPalindrome(head));
    }

    public static boolean isPalindrome(ListNode head) {
        List<Integer> list = new ArrayList<>();
        while (head != null) {
            list.add(head.val);
            head = head.next;
        }
        if(list.size()  < 2) return true;
        for (int i = 0, j = list.size() - 1; i <= j; i++,j--) {
            if (!list.get(i).equals(list.get(j))) return false;
        }

        return true;
    }

}
